package delivery.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import javax.swing.JOptionPane;

import com.mysql.jdbc.PreparedStatement;

import delivery.bean.ItemMenuBean;
import delivery.connection.Conexao;

public class ItemMenuDao extends Conexao {
	private String tabela;

	public ItemMenuDao() {
		this.tabela = "item_menu";
	}

	public ArrayList<ItemMenuBean> getItemPorPermissao(int id_permissao) {
		String sql = "SELECT * FROM " + this.tabela + " WHERE id_permissao = ?";
		ArrayList<ItemMenuBean> itemMenu = new ArrayList<ItemMenuBean>();

		try {
			PreparedStatement pS = (PreparedStatement) this.getConn()
					.prepareStatement(sql);

			pS.setInt(1, id_permissao);
			ResultSet rS = pS.executeQuery();

			while (rS.next()) {
				ItemMenuBean item = new ItemMenuBean();
				item.setId_item_menu(rS.getInt("id_item_menu"));
				item.setId_permissao(rS.getInt("id_permissao"));
				item.setUrl(rS.getString("url"));
				item.setDescricao(rS.getString("descricao"));
				itemMenu.add(item);
			}
		} catch (SQLException erro) {
			JOptionPane.showMessageDialog(null, erro.getMessage());
		}

		return itemMenu;
	}
}
